{extend name="common:base" /}

{block name="page_title"}{$controllerName}列表{/block}
{block name="style"}
{/block}
{block name="content"}
<div class="row">
    <div class="col-xs-1 goods-type-box">
        <div class="box box-solid">
            <div class="box-header with-border">
                <h3 class="box-title">类型</h3>
            </div>
            <div class="box-body no-padding">
                <ul class="nav nav-pills nav-stacked">
                    <li {if(1 == $show)}class="active"{/if}><a href="{:url('',['show'=>1])}">出售中<span class="pull-right total">{$showNum['1']}</span></a></li>
                    <li {if(2 == $show)}class="active"{/if}><a href="{:url('',['show'=>2])}">已售罄<span class="pull-right total">{$showNum['2']}</span></a></li>
                    <li {if(3 == $show)}class="active"{/if}><a href="{:url('',['show'=>3])}">仓库中<span class="pull-right total">{$showNum['3']}</span></a></li>
                    <li {if(4 == $show)}class="active"{/if}><a href="{:url('',['show'=>4])}">回收站<span class="pull-right total">{$showNum['4']}</span></a></li>
                </ul>
            </div>
            <!-- /.box-body -->
        </div>
    </div>
    <div class="col-xs-11">
        <div class="box box-primary">
            <div class="box-header with-border">
                <div class="row">
                    <div class="col-xs-11">
                        {if(count($whereKeys))}
                        <form method="get" class="form-inline" action="{:url('index')}">
                            {volist name="whereKeys" id="v"}
                            {switch $v['type']}
                            {case text}
                            <div class="input-group">
                                <input type="text" name="search[{$v['key']}]" class="form-control" placeholder="{$v['text']}" value="{$search[$v['key']]}">
                            </div>
                            {/case}
                            {case value="select|select_empty|radio"}
                            <div class="input-group">
                                <select name="search[{$v['key']}]" class="form-control">
                                    <option value="">{$v['text']}</option>
                                    <?php echo(getSelectHtml($v,$search[$v['key']])); ?>
                                </select>
                            </div>
                            {/case}
                            {case select_source}
                            <div class="input-group">
                                <select name="search[{$v['key']}]" class="form-control">
                                    <option value="">{$v['text']}</option>
                                    <?php echo(getSelectHtml($v,$search[$v['key']],$selectList[$v['type_value_custom']['source']])); ?>
                                </select>
                            </div>
                            {/case}
                            {/switch}
                            {/volist}
                            <div class="btn-group">
                                <button type="submit" class="btn btn-primary">搜索</button>
                                <a class="btn btn-success" href="{:url('index')}">全部</a>
                            </div>
                        </form>
                        {/if}
                    </div>
                    <div class="col-xs-1">
                        <div class="btn-group">
                            <a href="{:url('add')}" class="btn btn-default">添加</a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="box-body">
                <table class="table table-striped table-bordered table-hover">
                    <thead>
                    <tr>
                        <th style="width:80px;text-align:center;">排序</th>
                        <th style="width:80px;">商品</th>
                        <th style="">&nbsp;</th>
                        <th style="width: 100px;">价格</th>
                        <th style="width: 60px">库存</th>
                        <th style="width: 60px">销量</th>
                        <th style="width: 120px">属性</th>
                        <th style="width: 60px">状态</th>
                        <th style="width: 120px">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {volist name="datas" id="v"}
                    <tr>
                        <td style="text-align:center;">
                            {$v['display_sort']}
                        </td>
                        <td>
                            <a href="javascript:;">
                                <img src="{:getGoodsThumb($v['thumbs'])}"
                                     style="width:72px;height:72px;padding:1px;border:1px solid #efefef;margin: 7px 0"
                                     onerror="goodsAvatarOnerror(this)">
                            </a>
                        </td>
                        <td>
                            <div>
                                <div style="width: 100%;">
                                    <a href="javascript:;" data-toggle="ajaxEdit" data-edit="textarea" data-href="" style="overflow : hidden;text-overflow: ellipsis;display: -webkit-box;-webkit-line-clamp: 2;-webkit-box-orient: vertical;">
                                        {$v['goods_name']}
                                    </a>
                                    <span class="catetag">
                                {volist name="v['cates']" id="c"}
                                <span class="text-danger">[{:getGoodsCates($listShowCategory,$c)}]</span>
                                {/volist}
                            </span>
                                </div>
                                <i class="icow icow-weibiaoti--" data-toggle="ajaxEdit2"></i>
                            </div>
                        </td>
                        <td>
                            {if($v['min_price'] == $v['max_price'])}
                            ￥{:fenToYuan($v['min_price'])}
                            {else /}
                            ￥{:fenToYuan($v['min_price'])}
                            <br>
                            ￥{:fenToYuan($v['max_price'])}
                            {/if}
                        </td>
                        <td>{$v['stock']}</td>
                        <td>{$v['sales']}</td>
                        <td>
                            <a href="javascript:;" class="{if(!empty($v['is_recommand']))}text-danger{else /}text-default{/if}"
                               data-toggle='ajaxSwitch'
                               data-switch-value="{$v['is_recommand']}"
                               data-switch-value0='0||text-default|{:url("change_attr",array("status"=>1,"attr"=>"recommand","id"=>hashIdEncode($v["id"])))}'
                               data-switch-value1='1||text-danger|{:url("change_attr",array("status"=>0,"attr"=>"recommand","id"=>hashIdEncode($v["id"])))}'
                            >热卖</a>
                            <a href="javascript:;" class="{if(!empty($v['is_new']))}text-danger{else /}text-default{/if}"
                               data-toggle='ajaxSwitch'
                               data-switch-value="{$v['is_new']}"
                               data-switch-value0='0||text-default|{:url("change_attr",array("status"=>1,"attr"=>"new","id"=>hashIdEncode($v["id"])))}'
                               data-switch-value1='1||text-danger|{:url("change_attr",array("status"=>0,"attr"=>"new","id"=>hashIdEncode($v["id"])))}'
                            >新品</a>
                            <a href="javascript:;" class="{if(!empty($v['is_hot']))}text-danger{else /}text-default{/if}"
                               data-toggle='ajaxSwitch'
                               data-switch-value="{$v['is_hot']}"
                               data-switch-value0='0||text-default|{:url("change_attr",array("status"=>1,"attr"=>"hot","id"=>hashIdEncode($v["id"])))}'
                               data-switch-value1='1||text-danger|{:url("change_attr",array("status"=>0,"attr"=>"hot","id"=>hashIdEncode($v["id"])))}'
                            >热销</a>
                        </td>
                        <td>
                            {$goodsSiteEnum['status'][$v['status']]}
                        </td>
                        <td>
                            <a href="{:url('edit',array('id'=>hashIdEncode($v['id'])))}">编辑</a>
                            {if($show != 4)}
                            <a class="confirm-rst-url-btn" href="{:url('del',array('id'=>hashIdEncode($v['id'])))}" data-info="你确定要删除吗？">删除</a>
                            {else /}
                            <a class="confirm-rst-url-btn" href="{:url('recovery',array('id'=>hashIdEncode($v['id'])))}" data-info="你确定要恢复吗？">恢复</a>
                            {/if}
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
            </div>
            <div class="box-footer clearfix">
                <div id="page1" class="pull-right"></div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script>
    var totalPages = {$totalPages};
    var pageIndex = {$pageIndex};
    laypage({
        cont: 'page1', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
        pages: totalPages, //通过后台拿到的总页数
        curr: pageIndex, //当前页
        skip: true, //是否开启跳页
        jump: function(obj, first){ //触发分页后的回调
            if(!first){ //点击跳页触发函数自身，并传递当前页：obj.curr
                location.href = "{$pageUrl|raw}" +  "&p=" + obj.curr
            }
        }
    });
</script>
<script>
    $(document).on("click", '[data-toggle="ajaxSwitch"]', function(e) {
        e.preventDefault();
        var obj = $(this),
            confirm = obj.data('msg') || obj.data('confirm'),
            othercss = obj.data('switch-css'),
            other = obj.data('switch-other'),
            refresh = obj.data('switch-refresh') || false;
        if (obj.attr('submitting') == '1') {
            return
        }
        var value = obj.data('switch-value'),
            value0 = obj.data('switch-value0'),
            value1 = obj.data('switch-value1');
        if (value === undefined || value0 === undefined || value1 === undefined) {
            return
        }
        var url, css, text, newvalue, newurl, newcss, newtext;
        value0 = value0.split('|');
        value1 = value1.split('|');
        if (value == value0[0]) {
            url = value0[3], css = value0[2], text = value0[1], newvalue = value1[0], newtext = value1[1], newcss = value1[2]
        } else {
            url = value1[3], css = value1[2], text = value1[1], newvalue = value0[0], newtext = value0[1], newcss = value0[2]
        }
        var html = obj.html();
        var submit = function() {
                $.post(url).done(function(json) {
                    if (json.code == 1) {
                        if (other && othercss) {
                            if (newvalue == '1') {
                                $(othercss).each(function() {
                                    if ($(this).data('switch-value') == newvalue) {
                                        this.className = css;
                                        $(this).data('switch-value', value).html(text || html)
                                    }
                                })
                            }
                        }
                        obj.data('switch-value', newvalue);
                        obj.html(newtext || html);
                        obj[0].className = newcss;
                        refresh && location.reload()
                    } else {
                        obj.html(html);
                        alert(json.msg)
                    }
                    obj.removeAttr('submitting')
                }).fail(function() {
                    obj.removeAttr('submitting');
                    obj.button('reset');
                    alert('遇到错误')
                })
            },
            a;
        if (confirm) {
            tip.confirm(confirm, function() {
                obj.html('<i class="fa fa-spinner fa-spin"></i>').attr('submitting', 1), submit()
            })
        } else {
            obj.html('<i class="fa fa-spinner fa-spin"></i>').attr('submitting', 1), submit()
        }
    });
</script>
{/block}